﻿namespace TfsCloudDeploy.Workflow.Core
{
    using System;
    using System.ComponentModel;
    using System.Text;
    using TfsCloudDeploy.Workflow.Core.Activities;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [Serializable, TypeConverter(typeof(PrePackageTransformSettingsConverter))]
    public class PrePackageTransformSettings
    {
        public PrePackageTransformSettings()
        {

        }

        public PrePackageTransformSettings(bool overrideSourceWebConfigWithTransformFilePrePackaging)
            : this()
        {
            this.OverrideSourceWebConfigWithTransformFilePrePackaging = overrideSourceWebConfigWithTransformFilePrePackaging;
        }

        [Browsable(true), RefreshProperties(RefreshProperties.All), DefaultValue(false), SRDisplayName(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.OverrideSourceWebConfigWithTransformFilePrePackagingDisplayName), SRDescription(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.OverrideSourceWebConfigWithTransformFilePrePackagingDescription)]
        public bool OverrideSourceWebConfigWithTransformFilePrePackaging { get; set; }

        [Browsable(true), RefreshProperties(RefreshProperties.All), SRDisplayName(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.OverrideTransformsDisplayName), SRDescription(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.OverrideTransformsDescription)]
        public OverrideTransform[] OverrideTransforms { get; set; }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            if (this.OverrideSourceWebConfigWithTransformFilePrePackaging)
            {
                builder.Append("Override Source Web.Config With Transform File Pre-Packaging");
            }

            if (OverrideTransforms != null && OverrideTransforms.Length > 0)
            {
                builder.AppendFormat(" [{0} overrides specified]", OverrideTransforms.Length);
            }

            string overrideSettingsDisplayText = builder.ToString();

            return string.IsNullOrWhiteSpace(overrideSettingsDisplayText) ? "Not Configured" : overrideSettingsDisplayText;
        }
    }
}
